using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Decav.Gatsb.Application.Configuration;

namespace Decav.Gatsb.Application.CommandInterpreters
{
    /// <summary>
    /// Gets help for the user.
    /// </summary>
    public class HelpCommandInterpreter : ICommandInterpreter
    {
        #region ICommandInterpreter Members

        public void Execute(CommandInterpreterContext context)
        {
            if (!context.MessageHasText || context.ResponseEnded)
                return;

            string body = context.InputMessage.Body.Trim();

            string detail = null;
            if (!context.FindCommand(_commandPrefixes, out detail))
                return;

            // This is looking for a place, so ignore it when parsing for help
            if (context.InputMessage.Body.StartsWith("?") && !string.IsNullOrEmpty(detail))
                return;

            string helpText = File.ReadAllText(GatsbApplicationConfigurationSection.Current.HelpTextPath);
            context.SendResponse(helpText);

            context.RemoveFirstBodyLine();
            context.EndResponse();
        }

        #endregion

        private static readonly string[] _commandPrefixes = new string[] { "?", "help" };
    }
}
